#ifndef GLOBALS_H
#define GLOBALS_H

#include <QString>
#include <QDebug>
#include <QTime>

namespace gl {

typedef float PcmSampleType;


typedef int64_t TicksTime; // ticks_time == sample_rate * number_of_secs;
typedef int64_t MidiTime; // midi_time == 120 * number_of_32rds

struct AudioPorts {
    AudioPorts();
    AudioPorts(int ins, int outs, size_t buf_size);
    ~AudioPorts();
    int nIns; int nOuts;
    gl::PcmSampleType** inputs;
    gl::PcmSampleType** outputs;
    size_t size;
};

const float k_pi = 3.14159;
const float k_pi_x_2 = k_pi * 2.;
const float k_default_bpm = 120.;
const int k_default_samplerate = 48000;
const int ticks_per_16th = 120; // default midi resolution


inline static void log(const QString logmsg){
    qDebug() << QTime::currentTime().toString("hh:mm:ss.zzz") <<
                "  "<<logmsg;
}

inline static void log(const QString logmsg, long long int i){
    qDebug() << QTime::currentTime().toString("hh:mm:ss.zzz") <<
                "  "<<logmsg.arg(i);
}

struct Tempo {
    Tempo(float bpm_new = k_default_bpm) : msec_per_quarter(k_msec_per_min / bpm_new){}
    static const float k_msec_per_min = 60000000.;
    float bpm(){return k_msec_per_min / msec_per_quarter;}
    long msec_per_quarter;
};

struct TimeSignature {
    TimeSignature(
        unsigned char numerator_new = 4,
        unsigned char denomenator_new = 4,
        unsigned char metronome_pulse_new = 24, // 24 = one click per quarter-note
        unsigned char notes_32_in_qtr_new = 8
        ) :
        numerator(numerator_new),
        denomenator(denomenator_new),
        metronome_pulse(metronome_pulse_new),
        notes_32_in_qtr(notes_32_in_qtr_new)
    {}
    unsigned char numerator;
    unsigned char denomenator;
    unsigned char metronome_pulse;
    unsigned char notes_32_in_qtr;
};
}

#endif // GLOBALS_H
